﻿#include "LifeIcon.h"

LifeIcon::LifeIcon(const QPoint& pos):Background(pos.x(),pos.y())
{
	addFrame("玩家生命");
	init();
	
}

void LifeIcon::init()
{
	QPoint pos = getPos();
	m_TextPos = getPos() - QPoint(0, getSize().height());
	
	move(m_TextPos);
	m_TextPos.setX(pos.x() + getSize().width());
	m_TextPos.setY(pos.y() - 15);

	m_NumFont.setPixelSize(35);
}

void LifeIcon::update()
{
	
}

void LifeIcon::draw(QPainter* painter)
{
	getModel()["正常"].draw(painter, getModelRect().topLeft());

	painter->setPen(m_NumPen);
	painter->setFont(m_NumFont);

	QString Num = QString::number(m_num);
	/*int w = painter->fontMetrics().horizontalAdvance(Num);
	int h = painter->fontMetrics().capHeight();
	m_TextPos.setY(m_TextPos.y());*/
	Num = "X" + Num;
	painter->drawText(m_TextPos,Num);
}

void LifeIcon::setNum(const int n)
{
	m_num = n;
}

const int LifeIcon::getTextWidth()
{
	QFontMetrics metrics(m_NumFont);
	return metrics.horizontalAdvance("X00");
}

const int LifeIcon::getTextHeight()
{
	QFontMetrics metrics(m_NumFont);
	return metrics.capHeight();
}
